

import 'package:flustars/flustars.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
// 
import 'package:get/get.dart';
import 'package:smart_freezer/core/resources/app_config.dart';
import 'package:smart_freezer/core/resources/icon_names.dart';
import 'package:smart_freezer/core/resources/routers.dart';
import 'package:smart_freezer/core/utils/local_storage.dart';
import 'package:smart_freezer/core/utils/tr_extension.dart';

import '../../generated/locale_keys.g.dart';

class HomeAddDevice extends StatefulWidget {
  const HomeAddDevice({Key? key}) : super(key: key);

  @override
  State<HomeAddDevice> createState() => _HomeAddDeviceState();
}

class _HomeAddDeviceState extends State<HomeAddDevice> {

  late TimerUtil mTimerUtil;
  int mTick = 10;
  int totalTime = 10; // 120s

  bool isDarkMode = LocalStorage.getThemeMode() == 1;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    mTimerUtil = TimerUtil(mInterval: 1000, mTotalTime: totalTime * 1000);
    // 开启倒计时
    mTimerUtil.startCountDown();
    mTimerUtil.setOnTimerTickCallback((millisUntilFinished) {
      final time = millisUntilFinished / 1000;
      setState(() {
        mTick = time.toInt();
      });
      if(mTick == 0) { // 跳到主页
        Get.offNamed(LCRouter.home);
        mTimerUtil.cancel();
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        // backgroundColor: Colors.white,
        elevation: 0,
        leadingWidth: 50,
        leading: InkWell(
          onTap: () {
            Get.back();
          },
          child: Container(
            padding: EdgeInsets.fromLTRB(0, 9, 0, 9),
            child: Icon(Icons.arrow_back_ios_rounded), //Image.asset(IconNames.nav_back, height: 10,),
          ),
        ),
      ),
      body: Container(
        color: isDarkMode ? Colors.black : Colors.white,
        width: MainCommon.screenWidth,
        alignment: Alignment.center,
        child: Column(
          children: [
            SizedBox(height: 140,),
            Image.asset(IconNames.bluetooth08, width: MainCommon.screenWidth * 0.6,),
            Text(LocaleKeys.add_device_register_device.trc(), style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),),
            SizedBox(height: 10,),
            Text(LocaleKeys.add_device_shenqing_tip.trc()),
            SizedBox(height: 10,),
            Text(LocaleKeys.add_device_enter_tip.pluralc(mTick)),
          ],
        ),
      ),
    );
  }
}
